package com.scqzy.shengchunqiang.sword2offer.day02;

import com.scqzy.shengchunqiang.structure.ListNode;

import java.util.Objects;

/**
 * @Description: 剑指 Offer 24. 反转链表
 * @Author 盛春强
 * @Date 2021/8/9 19:59
 */
public class ReverseList {
    public ListNode reverseList(ListNode head) {
        ListNode pre = null;
        ListNode node = head;
        while (Objects.nonNull(node)) {
            ListNode tmp;
            tmp = node.next;
            node.next = pre;
            pre = node;
            node = tmp;
        }
        return pre;
    }
}
